package com.dgh.school.controller;

import com.dgh.school.bean.Department;
import com.dgh.school.common.R;
import com.dgh.school.service.DepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 部门管理的控制层
 *
 */
@RestController
public class DepartmentController {

    @Autowired
    private DepartmentService departmentService;

    @RequestMapping("/department/departments")
    public R selectByPage(int pageNum, int pageSize){
        try {
            return departmentService.selectByPage(pageNum,pageSize);
        } catch (Exception e) {
            return R.error();
        }
    }

    @RequestMapping("/department/delete")
    public R deleteById(int id){
        try {
            departmentService.deleteById(id);
            System.out.println(id);
            return R.ok();
        } catch (Exception e) {
            return R.error();
        }
    }

    @RequestMapping("/department/add")
    public R add(Department de){
        try {
            departmentService.insertData(de);
            System.out.println(de);
            return R.ok();
        } catch (Exception e) {
            return R.error();
        }
    }

    @RequestMapping("/department/modify")
    public R modify(Department de){
        try {
            departmentService.updateData(de);
            System.out.println(de);
            return R.ok();
        } catch (Exception e) {
            return R.error();
        }
    }

    @RequestMapping("/department/departmentall")
    public R selectAll(){
        try {

            departmentService.selectAlldepartments();
            System.out.println();
            return departmentService.selectAlldepartments();
        } catch (Exception e) {
            return R.error();
        }
    }

}
